package com.huawei.appgallery.forum.comments.card;

import android.content.Context;
import android.content.Intent;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.PopupMenu;
import android.widget.PopupMenu.OnMenuItemClickListener;
import android.widget.RelativeLayout;
import android.widget.TextView;
import androidx.annotation.RequiresApi;
import com.huawei.appgallery.forum.base.card.ForumCard;
import com.huawei.appgallery.forum.base.card.bean.Reply;
import com.huawei.appgallery.forum.base.card.bean.Reply.b;
import com.huawei.appgallery.forum.base.card.bean.User;
import com.huawei.appgallery.forum.cards.widget.ReplyTextView;
import com.huawei.appgallery.forum.user.api.IUserHomePageProtocol;
import com.huawei.appgallery.foundation.account.bean.UserSession;
import com.huawei.appgallery.foundation.ui.framework.cardkit.bean.CardBean;
import o.azb;
import o.bse;
import o.bsy;
import o.btc;
import o.bue;
import o.bue.d;
import o.bue.e;
import o.bue.h;
import o.bue.j;
import o.buj;
import o.bwx;
import o.bxv;
import o.cgz;
import o.chy;
import o.evk;
import o.evx;
import o.fho;
import o.fiu;
import o.fjb;
import o.fjo;
import o.fjq;
import o.ll;

public class ForumReplyCard extends ForumCard {
    private View ʻ;
    private String ʻॱ;
    private TextView ʼ;
    private ImageView ʽ;
    private Reply ˊ;
    private bwx ˊॱ;
    private ReplyTextView ˋ;
    private PopupMenu ˋॱ;
    private TextView ˎ;
    private buj ˏ = null;
    private long ˏॱ;
    private LinearLayout ͺ;
    private Context ॱ;
    private RelativeLayout ॱˊ;
    private boolean ॱˎ = false;
    private LinearLayout ॱॱ;
    private LinearLayout ᐝ;

    public ForumReplyCard(Context context) {
        super(context);
        this.ॱ = context;
        this.ˊॱ = (bwx) fho.ˏ().ˋ("Operation").ॱ(bwx.class);
        if (this.ॱ instanceof buj) {
            this.ˏ = (buj) this.ॱ;
        }
    }

    public cgz ˏ(View view) {
        ʽ(view);
        this.ˋ = (ReplyTextView) view.findViewById(e.ˎˏ);
        this.ˋ.setShowHostStamp(true);
        this.ˋ.setShowModeratorStamp(true);
        this.ˋ.setHostPriority(this.ˋ.ˊ() + 1);
        this.ˎ = (TextView) view.findViewById(e.ˏˏ);
        this.ʼ = (TextView) view.findViewById(e.ˉ);
        this.ᐝ = (LinearLayout) view.findViewById(e.ॱˋ);
        this.ᐝ.setOnClickListener(new OnClickListener(this) {
            final /* synthetic */ ForumReplyCard ˏ;

            {
                this.ˏ = r1;
            }

            public void onClick(View view) {
                this.ˏ.ᐝ();
            }
        });
        this.ॱˊ = (RelativeLayout) view.findViewById(e.ˋˋ);
        this.ʻ = view.findViewById(e.ˋॱ);
        azb.ˋ(this.ʻ);
        this.ʽ = (ImageView) view.findViewById(e.ˎˎ);
        this.ॱॱ = (LinearLayout) view.findViewById(e.ʻॱ);
        this.ͺ = (LinearLayout) view.findViewById(e.ˊᐝ);
        azb.ˏ(view, e.ˊᐝ);
        return this;
    }

    @RequiresApi(api = 21)
    public void ˏ(CardBean cardBean) {
        super.ˏ(cardBean);
        if (cardBean instanceof ForumReplyCardBean) {
            ForumReplyCardBean forumReplyCardBean = (ForumReplyCardBean) cardBean;
            this.ʻॱ = forumReplyCardBean.ॱ();
            this.ˊ = forumReplyCardBean.ˊ();
            if (this.ˊ != null) {
                this.ॱˎ = this.ˊ.ॱ().ʼ();
                ˎ();
                ˋ(this.ˋ, this.ˊ, forumReplyCardBean.ॱ());
                ˊ(this.ˋ, this.ˊ);
                ˊ(this.ˎ, btc.ˏ(this.ॱ, this.ˊ.ˏ()));
                this.ˏॱ = this.ˊ.ˊ();
                if (cardBean.ॱᐨ()) {
                    if (ʻ()) {
                        this.ʼ.setText(this.ॱ.getString(j.ˏॱ) + this.ˏ.ˊ());
                        this.ᐝ.setVisibility(0);
                    } else {
                        this.ᐝ.setVisibility(8);
                    }
                    this.ʻ.setVisibility(8);
                } else {
                    this.ʻ.setVisibility(0);
                    this.ᐝ.setVisibility(8);
                }
                ʽ();
                ʼ();
            }
        }
    }

    private void ˎ() {
        if (this.ˊ.ʽ().ˊ() != b.ˊ.ˊ()) {
            this.ॱॱ.setVisibility(8);
        } else if (this.ˏ.R_() || this.ॱˎ) {
            this.ॱॱ.setVisibility(0);
        } else {
            this.ˊ.ˎ(this.ॱ.getString(bsy.j.ʼॱ));
            this.ॱॱ.setVisibility(8);
        }
    }

    private void ʼ() {
        long ʻ = this.ˏ.ʻ();
        if (ʻ == 0 || this.ˊ.ˊ() != ʻ) {
            this.ͺ.setBackground(this.ॱ.getResources().getDrawable(d.ʽ));
        } else {
            this.ͺ.setBackground(this.ॱ.getResources().getDrawable(d.ॱ));
        }
    }

    private void ʽ() {
        if (this.ˊ.ʽ().ˊ() != b.ˊ.ˊ() || this.ˏ.R_()) {
            this.ʽ.setBackgroundResource(d.ʻ);
            this.ॱˊ.setOnClickListener(new OnClickListener(this) {
                final /* synthetic */ ForumReplyCard ˊ;

                {
                    this.ˊ = r1;
                }

                public void onClick(View view) {
                    this.ˊ.ˊ(view);
                }
            });
            this.ॱˊ.setBackground(this.ॱ.getResources().getDrawable(d.ˎ));
            return;
        }
        this.ʽ.setBackgroundResource(d.ᐝ);
        this.ॱˊ.setOnClickListener(null);
        this.ॱˊ.setBackground(null);
    }

    public void ॱ(final chy o_chy) {
        ˉ().setOnClickListener(new evx(this) {
            final /* synthetic */ ForumReplyCard ˎ;

            public void ˋ(View view) {
                o_chy.ˏ(0, this.ˎ);
                if (this.ˎ.ˊ != null) {
                    if (this.ˎ.ˊ.ʽ().ˊ() == b.ˊ.ˊ()) {
                        evk.ˏ(this.ˎ.ॱ.getString(bse.ˏ.ॱ(400013).ˏ()));
                    } else {
                        this.ˎ.ˎ(this.ˎ.ˊ.ॱ());
                    }
                }
            }
        });
    }

    private void ˊ(View view) {
        this.ˋॱ = new PopupMenu(this.ॱ, view);
        this.ˋॱ.getMenuInflater().inflate(h.ˊ, this.ˋॱ.getMenu());
        if (UserSession.getInstance().isLoginSuccessful() && this.ॱˎ) {
            this.ˋॱ.getMenu().findItem(e.ˊˊ).setVisible(false);
            this.ˋॱ.getMenu().findItem(e.ʽ).setVisible(true);
        } else {
            this.ˋॱ.getMenu().findItem(e.ˊˊ).setVisible(true);
            this.ˋॱ.getMenu().findItem(e.ʽ).setVisible(false);
        }
        this.ˋॱ.getMenu().findItem(e.ʼॱ).setVisible(false);
        this.ˋॱ.setOnMenuItemClickListener(new OnMenuItemClickListener(this) {
            final /* synthetic */ ForumReplyCard ˊ;

            {
                this.ˊ = r1;
            }

            public boolean onMenuItemClick(MenuItem menuItem) {
                boolean z;
                int itemId = menuItem.getItemId();
                if (itemId == e.ʽ) {
                    this.ˊ.ˊॱ.ˊ(this.ˊ.ॱ, this.ˊ.ˏॱ, this.ˊ.ʻॱ).ˏ(new fjq<Boolean>(this) {
                        final /* synthetic */ AnonymousClass4 ˊ;

                        {
                            this.ˊ = r1;
                        }

                        public void onComplete(fjo<Boolean> o_fjo_java_lang_Boolean) {
                            if (o_fjo_java_lang_Boolean.ˊ() && ((Boolean) o_fjo_java_lang_Boolean.ॱ()).booleanValue()) {
                                this.ˊ.ˊ.ˎ(this.ˊ.ˊ.ˏॱ);
                            }
                        }
                    });
                    z = true;
                } else if (itemId == e.ˊˊ) {
                    this.ˊ.ˊॱ.ˎ(this.ˊ.ॱ, new bxv.d(this.ˊ.ˊ.ॱ().ˎ(), this.ˊ.ˊ.ॱ().ˋ(), 2, this.ˊ.ˏॱ).ˎ(this.ˊ.ˊ.ˋ()).ˏ(this.ˊ.ʻॱ).ˎ());
                    z = true;
                } else {
                    z = false;
                }
                if (z) {
                    this.ˊ.ˋॱ.dismiss();
                }
                return false;
            }
        });
        this.ˋॱ.show();
    }

    private void ˎ(User user) {
        Intent intent = new Intent("forum.comments.reply");
        if (!user.ʼ()) {
            intent.putExtra("from_user", user);
        }
        ll.ˏ(this.ॱ).ˋ(intent);
    }

    private void ˎ(long j) {
        Intent intent = new Intent("forum.comments.delete");
        intent.putExtra("reply_id", j);
        ll.ˏ(this.ॱ).ˋ(intent);
    }

    private void ˋ(ReplyTextView replyTextView, final Reply reply, String str) {
        final fjb ˎ = fho.ˏ().ˋ("User").ˎ("UserHomePageActivity");
        final IUserHomePageProtocol iUserHomePageProtocol = (IUserHomePageProtocol) ˎ.ˊ();
        iUserHomePageProtocol.setUri("forum|user_detail");
        iUserHomePageProtocol.setDomainId(str);
        replyTextView.setVisibility(0);
        replyTextView.setData(reply, new OnClickListener(this) {
            final /* synthetic */ ForumReplyCard ˎ;

            public void onClick(View view) {
                iUserHomePageProtocol.setType(reply.ॱ().ˊ());
                iUserHomePageProtocol.setUserId(reply.ॱ().ॱ());
                fiu.ˊ().ˏ(this.ˎ.ˉ().getContext(), ˎ);
            }
        }, new OnClickListener(this) {
            final /* synthetic */ ForumReplyCard ॱ;

            public void onClick(View view) {
                iUserHomePageProtocol.setType(reply.ˎ().ˊ());
                iUserHomePageProtocol.setUserId(reply.ˎ().ॱ());
                fiu.ˊ().ˏ(this.ॱ.ˉ().getContext(), ˎ);
            }
        }, new OnClickListener(this) {
            final /* synthetic */ ForumReplyCard ॱ;

            public void onClick(View view) {
                if (reply.ʽ().ˊ() == b.ˊ.ˊ()) {
                    evk.ˏ(this.ॱ.ॱ.getString(bse.ˏ.ॱ(400013).ˏ()));
                } else {
                    this.ॱ.ˎ(this.ॱ.ˊ.ॱ());
                }
            }
        }, null);
    }

    private boolean ʻ() {
        int P_ = this.ˏ.P_();
        buj o_buj = this.ˏ;
        if (P_ == 2 && this.ˏ.Q_() > 5 && this.ˏ.ॱॱ() == 1) {
            return true;
        }
        return false;
    }

    private void ᐝ() {
        ll.ˏ(this.ॱ).ˋ(new Intent("forum.comments.list.refresh.all"));
    }

    private void ˊ(ReplyTextView replyTextView, Reply reply) {
        if (reply.ʽ().ˊ() != b.ˊ.ˊ() || this.ˏ.R_()) {
            replyTextView.setTextColor(this.ॱ.getResources().getColor(bue.b.ˎ));
        } else {
            replyTextView.setTextColor(this.ॱ.getResources().getColor(bue.b.ˋ));
        }
    }
}
